﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using ElectronicsMarket.Service.Models;
using ElectronicsMarket.Service.IService;
using ElectronicsMarket.Service.ServiceImpl;
using System.Drawing;

namespace ElectronicsMarket.Service.ReleaseServices
{
    /// <summary>
    /// Summary description for ServicesRelease
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ServicesRelease : System.Web.Services.WebService
    {
        IProductService productService = new ProductServiceImpl();
        ICategoryService categoryService = new CategoryServiceImpl();
        IUserService userService = new UserServiceImpl();
        IStaffService staffService = new StaffServiceImpl();
        IManufactureService manufactureService = new ManufactureServiceImpl();
        IConvertPicture converpicture = new ConverPictureImpl();
        IReceipt receiptServices=new ReceiptImpl();
        IReceiptDetail receiptdetailServices= new ReceiptDetailImpl();
        IDepartment departmentServices= new DepartmentImpl();
        IOrderService orderServices = new OrdersImpl();
        IOrderDetailsServices orderDetailServices = new OrderDetailsImpl();
        ICustomer customerServices = new CustomerImpl();
        IInventoryService inventoryService = new InventoryServiceImpl();
        IBillboardServcies bilboardservices = new BillboardImpl();

        #region Product Service
        [WebMethod]
        public List<PRODUCT> getProductList()
        {
            return productService.getProductList().ToList();
        }

        [WebMethod]
        public List<PRODUCT> getNewProduct()
        {
            return productService.getNewProduct().ToList();
        }

        [WebMethod]
        public List<PRODUCT> getTopProduct()
        {
            return productService.getTopProduct();
        }

        [WebMethod]
        public List<PRODUCT> getProductByName(string productName)
        {
            return productService.getProductByName(productName);
        }

        [WebMethod]
        public PRODUCT getProductById(long productId)
        {
            return productService.getProductById(productId);
        }

        [WebMethod]
        public void insertProduct(PRODUCT product)
        {
            productService.insertProduct(product);
        }

        [WebMethod]
        public void deleteProduct(PRODUCT product)
        {
            productService.deleteProduct(product);
        }

        [WebMethod]
        public void updateProduct(PRODUCT product)
        {
            productService.updateProduct(product);
        }
        #endregion

        #region Category Service
        [WebMethod]
        public List<CATEGORY> getAllCategory()
        {
            return categoryService.getAllCategory().ToList();
        }

        public CATEGORY getCategoryById(int categoryId)
        {
            return categoryService.getCategoryById(categoryId);
        }
        #endregion

        #region User Service
        [WebMethod]
        public CUSTOMER getUserById(int userId)
        {
            CUSTOMER customer = userService.getUserById(userId);
            return customer;
        }

        [WebMethod]
        public CUSTOMER getUserByUsernameAndPassword(string username, string password)
        {
            CUSTOMER customer = userService.getUserByUsernameAndPassword(username, password);
            return customer;
        }

        [WebMethod]
        public bool addNewCustomer(int customerId, string username, string password, string email, DateTime registerDate, string firstName, string lastName, string address, string phoneNumber, DateTime birthday, bool sex)
        {
            return userService.addNewUser(customerId, username, password, email, registerDate, firstName, lastName, address, phoneNumber, birthday, sex);
        }

        [WebMethod]
        public int getLastUserId()
        {
            return userService.getLastUserId();
        }

        [WebMethod]
        public bool editUser(int userId, string address, string email)
        {
            return userService.editUser(userId, address, email);
        }
        #endregion

        #region Staff Servcies
        [WebMethod]
        public List<STAFF> getAllStaff()
        {
            return staffService.getAllStaff();

        }

        [WebMethod]
        public void updateStaff(STAFF staff)
        {
            staffService.updateStaff(staff);
        }
        [WebMethod]
        public STAFF getStaffByName(string tentruynhap, string pass)
        {
            return staffService.getStaffByName(tentruynhap, pass);
        }

        [WebMethod]
        public void insertStaff(STAFF staff)
        {
            staffService.insertStaff(staff);

        }
        [WebMethod]
        public void deleteStaff(STAFF staff)
        {
            staffService.deleteStaff(staff);
        }
        [WebMethod]
        public long getLastProduciId()
        {
            return staffService.getLastStaffId();
        }
        #endregion

        #region Manufacture Service
        [WebMethod]
        public List<MANUFACTURE> getAllManufacture()
        {
            return manufactureService.getAllManufacture();
        }

        [WebMethod]
        public MANUFACTURE getManufactureById(int manufactureId)
        {
            return manufactureService.getManufactureById(manufactureId);
        }
        #endregion

        #region Inventory Service
        [WebMethod]
        public int getQuantityOfProduct(long productId)
        {
            return inventoryService.getQuantityOfProduct(productId);
        }
	    #endregion

        #region ConvertPicture
        [WebMethod]
        public Image ConvertFromBinary(byte[] pic_byte)
        {
            return converpicture.BinaryconvertToPicture(pic_byte);
        }
        [WebMethod]
        public byte[] ConvertFromImage(Image image)
        {
            return converpicture.PictureconvertToBinary(image);
        }

        #endregion

        #region Receipt
        [WebMethod]
        public void InsertReceipt(RECEIPT Receipt)
        {
            receiptServices.InsertReceipt(Receipt);
        }
        //
        [WebMethod]
        public void updateReceipt(RECEIPT receipt)
        {
            receiptServices.UpdateReceipt(receipt);
        }
        [WebMethod]
        public long getLastPreceiptId()
        {
            return receiptServices.getLastPreceiptId();
        }
        #endregion
        
        #region Receipt_Detail
        [WebMethod]
        public void InsertReceiptDetail(RECEIPT_DETAIL ReceipDetail)
        {
           receiptdetailServices.InsertReceiptDetail(ReceipDetail);
        }
        #endregion

        #region Department
        [WebMethod]
        public List<DEPARTMENT> getAllDepartment()
        {
            return departmentServices.getAllDepartment();
        }
        #endregion

        #region Orders

        [WebMethod]
        public List<ORDER> getAllOrders()
        {
            return orderServices.getAllOrder();
        }

        [WebMethod]
        public void updateOrder(ORDER order)
        {
            orderServices.updateOrder(order);
        }

        [WebMethod]
        public bool createNewOrder(int customerId, long orderId)
        {
            return orderServices.createNewOrder(customerId, orderId);
        }

        [WebMethod]
        public long getLastOrderId() 
        {
            return orderServices.getLastOrderId();
        }
        #endregion

        #region OrderDetails
        [WebMethod]
        public List<ORDERS_DETAIL> getOrderDetailsByID(int id)
        {
            return orderDetailServices.getOrderDetailByID(id);
        }

        [WebMethod]
        public bool addNewOrderDetail(long orderId, long productId, int amount, decimal price)
        {
            return orderDetailServices.addNewOrderDetail(orderId, productId, amount, price);
        }
        #endregion

        #region Customer Service
        [WebMethod]
        public CUSTOMER getCustmerByID(int id)
        {
            return customerServices.getCustomerByID(id);
        }
        [WebMethod]
        public List<CUSTOMER> getAllCustomer()
        {
            return customerServices.getAllCustomer();
        }
        #endregion

        #region Billboard

        [WebMethod]
        public List<BILLBOAD> getAllBillboard()
        {
            return bilboardservices.getAllBillboard();
        }
        [WebMethod] 
        public void deleteBillboard(BILLBOAD billboard)
        {
            bilboardservices.deleteBillboard(billboard);
            
        }
        [WebMethod]
        public void updateBillboard(BILLBOAD billboard)
        {
            bilboardservices.updateBillboard(billboard);
        }
        [WebMethod]
        public void insertBillboard(BILLBOAD billboard)
        {
            bilboardservices.insertBillboard(billboard);
        }
        [WebMethod]
        public long getLastBillboardiId()
        {
            return bilboardservices.getLastBillboardiId();
        }
    
        #endregion
    }
}
